<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>新增页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body>

        <form class="layui-form" action="">

            <div class="mainBox">
                <div class="main-container mr-5">
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">mall_id</label>
                        <div class="layui-input-block">
                            <input type="number" name="mall_id" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">mch_id</label>
                        <div class="layui-input-block">
                            <input type="number" name="mch_id" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">优惠劵名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">优惠券来源：1-政府补贴结算券;2-商家结算平台券；3-平台优惠券；4-第三方券</label>
                        <div class="layui-input-block">
                            <input type="number" name="source_type" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">状态:0-未启用；1-正常；2-已下架</label>
                        <div class="layui-input-block">
                            <input type="number" name="status" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">券的结算价（价值），单位：分</label>
                        <div class="layui-input-block">
                            <input type="number" name="coupon_value" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">发放数量, -1 - 则表示不限制</label>
                        <div class="layui-input-block">
                            <input type="number" name="total_count" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">每人限领个数, -1 - 则表示不限制</label>
                        <div class="layui-input-block">
                            <input type="number" name="take_limit_count" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">领取方式：1-直接领取；2-后台发放；3-秒杀获取</label>
                        <div class="layui-input-block">
                            <input type="number" name="take_type" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">是否设置满多少金额可用，单位：分</label>
                        <div class="layui-input-block">
                            <input type="number" name="use_price" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">适用商品范围类型：1-一卡通年卡</label>
                        <div class="layui-input-block">
                            <input type="number" name="use_scope_type" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品范围编号的数组</label>
                        <div class="layui-input-block">
                            <input type="text" name="use_scope_values" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">使用说明</label>
                        <div class="layui-input-block">
                            <textarea name="use_instruction" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">指定使用门店</label>
                        <div class="layui-input-block">
                            <input type="text" name="shop_values" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">生效日期类型：1-固定日期区间；2-领取之后</label>
                        <div class="layui-input-block">
                            <input type="number" name="validity_type" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">固定日期-生效开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="valid_start_time" id="valid_start_time" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">固定日期-生效结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="valid_end_time" id="valid_end_time" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">领取日期-开始天数</label>
                        <div class="layui-input-block">
                            <input type="number" name="fixed_start_term" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">领取日期-结束天数</label>
                        <div class="layui-input-block">
                            <input type="number" name="fixed_end_term" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">优惠类型：1-代金券 ；2-折扣券</label>
                        <div class="layui-input-block">
                            <input type="number" name="discount_type" value="" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">折扣百分比</label>
                        <div class="layui-input-block">
                            <input type="number" name="discount_percent" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">优惠金额，单位：分</label>
                        <div class="layui-input-block">
                            <input type="number" name="discount_price" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">折扣上限，仅在 {@link #preferentialType} 等于 2 时生效。
                         *
                         * 例如，折扣上限为 20 元，当使用 8 折优惠券，订单金额为 1000 元时，最高只可折扣 20 元，而非 80  元。</label>
                        <div class="layui-input-block">
                            <input type="number" name="discount_limit_price" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">领取优惠券的数量</label>
                        <div class="layui-input-block">
                            <input type="number" name="take_count" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">使用优惠券的次数</label>
                        <div class="layui-input-block">
                            <input type="number" name="use_count" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">沃支付创建的活动ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="wo_act_id" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否有卡号:0-没有，1-有</label>
                        <div class="layui-input-block">
                            <input type="number" name="cardid_flag" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否有卡密:0-没有，1-有</label>
                        <div class="layui-input-block">
                            <input type="number" name="charg_flag" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否是否为动态链接:0-没有，1-有</label>
                        <div class="layui-input-block">
                            <input type="number" name="pwd_flag" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">备用字段1</label>
                        <div class="layui-input-block">
                            <input type="text" name="backup1" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">备用字段2</label>
                        <div class="layui-input-block">
                            <input type="text" name="backup2" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <input type="text" name="remark" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">创建者</label>
                        <div class="layui-input-block">
                            <input type="text" name="creator" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="create_time" id="create_time" value="CURRENT_TIMESTAMP" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">更新者</label>
                        <div class="layui-input-block">
                            <input type="text" name="updater" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">更新时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="update_time" id="update_time" value="CURRENT_TIMESTAMP" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否删除</label>
                        <div class="layui-input-block">
                            <input type="text" name="deleted" value="b'0'" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">租户编号</label>
                        <div class="layui-input-block">
                            <input type="number" name="tenant_id" value="0" class="layui-input">
                        </div>
                    </div>
                    
                </div>
            </div>

            <div class="bottom">
                <div class="button-container">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                        lay-filter="save">
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        重置
                    </button>
                </div>
            </div>
            
        </form>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        
        <script>

            // 相关接口
            const INSERT_API = "/app/admin/tejian-onecard-coupon-template/insert";
            
            // 字段 固定日期-生效开始时间 valid_start_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#valid_start_time",
                    type: "datetime",
                });
            })
            
            // 字段 固定日期-生效结束时间 valid_end_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#valid_end_time",
                    type: "datetime",
                });
            })
            
            // 字段 创建时间 create_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#create_time",
                    type: "datetime",
                });
            })
            
            // 字段 更新时间 update_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#update_time",
                    type: "datetime",
                });
            })
            
            //提交事件
            layui.use(["form", "popup"], function () {
                // 字段验证允许为空
                layui.form.verify({
                    phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
                    email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
                    url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
                    number: [/(^$)|^\d+$/,'只能填写数字'],
                    date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
                    identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
                });
                layui.form.on("submit(save)", function (data) {
                    layui.$.ajax({
                        url: INSERT_API,
                        type: "POST",
                        dateType: "json",
                        data: data.field,
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功", function () {
                                parent.refreshTable();
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });

        </script>

    </body>
</html>
